package de.bbl.android.activities;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import de.bbl.android.BBLAndroidFragmentActivity;
import de.bbl.android.R;

public class NewsExpandedActivity extends Activity {
	
	public void onCreate(Bundle bundle) 
    {
        super.onCreate(bundle);
        setContentView(R.layout.expanded_layout_news);
        
        String[] rssFeed = new String[3];
        Intent intent = getIntent();
        String[] pics = null;
        
        if (intent != null)
        {
            Bundle b = intent.getBundleExtra("android.intent.extra.INTENT");
            if (b == null)
            {
                rssFeed[0] = "Wrong Paramter...";
            }
            else
            {
            	rssFeed[0] = b.getString("pubdate") + "\n";
            	rssFeed[1] = b.getString("title") + "\n";
            	rssFeed[2] = b.getString("description") + "\n";
                if (b.getStringArray("pics") != null && b.getStringArray("pics")[0] != null)
                	pics = b.getStringArray("pics");
            }
        }
        else
        {
            rssFeed[0] = "No Information found for this feed...";
        
        }        
        final TextView date = (TextView) findViewById(R.id.storybox_date);
        final TextView titel = (TextView) findViewById(R.id.storybox_titel);
        final TextView description = (TextView) findViewById(R.id.storybox_description);
        final ImageView picture = (ImageView) findViewById(R.id.storybox_picture);

        date.setText(rssFeed[0]);
        if (rssFeed[1] != null && rssFeed[2] != null) {
        	titel.setText(rssFeed[1]);
        	description.setText(rssFeed[2]);
        }        
        if (pics != null) {
        	String tempUrl = pics[0].substring(0,pics[0].lastIndexOf("/") -1);
        	tempUrl = tempUrl.substring(tempUrl.lastIndexOf("/") + 1) + "_" + pics[0].substring(pics[0].lastIndexOf("/") + 1); 

        	Bitmap bm = BitmapFactory.decodeFile(BBLAndroidFragmentActivity.bbl_temp_img_sd_path + tempUrl);
        	picture.setImageBitmap(bm);
            for (int i = 1; i < pics.length; i++ ) {
            	tempUrl = pics[i].substring(0,pics[i].lastIndexOf("/") -1);
            	tempUrl = tempUrl.substring(tempUrl.lastIndexOf("/") + 1) + "_" + pics[i].substring(pics[i].lastIndexOf("/") + 1); 
            	bm = BitmapFactory.decodeFile(BBLAndroidFragmentActivity.bbl_temp_img_sd_path + tempUrl);
            	LinearLayout imageScrollLayout = (LinearLayout)findViewById(R.id.LayoutScrollView);
            	ImageView temp = new ImageView(getApplicationContext());
            	temp.setImageBitmap(bm);
            	imageScrollLayout.addView(temp);
            }
        } else {
        	picture.setVisibility(View.INVISIBLE);
        }
        
    }
}
